local pokerlib = require "club.threecard.pokerlib"
local gamelib = require "club.threecard.gamelib"

local poker_data = {}

local log = gamelib.logging.get("poker_data");

local clientTypeConfig = 
{
    [0] = pokerlib.core.poker_type.hei;
    [1] = pokerlib.core.poker_type.hong;
    [2] = pokerlib.core.poker_type.hua;
    [3] = pokerlib.core.poker_type.pian;
}

local clientValueConfig = 
{
    [1] = 2;
    [2] = 3;
    [3] = 4;
    [4] = 5;
    [5] = 6;
    [6] = 7;
    [7] = 8;
    [8] = 9;
    [9] = 10;
    [10] = 11;
    [11] = 12;
    [12] = 13;
    [13] = 1;
}

function poker_data.new(serverValue)
    local self = {};
    setmetatable(self, {__index = poker_data})

    if serverValue <= 0 then
        self.client_type = pokerlib.core.poker_type.null;
        self.client_value = -1;
        self.client_weight = 0;
        self.server_value = serverValue;
        return self;
    end

    self.server_value =  serverValue;
    serverValue = (serverValue - 1) % 52;
    self.client_value = clientValueConfig[math.floor(serverValue/4+1)];
    self.client_type = clientTypeConfig[math.floor(serverValue%4)];
    self.client_weight = self.client_value;
    
    if self.client_value > 13 and self.client_value < 1 then
        log.error(self.client_value);
    end

    return self;
end

function poker_data:tostring()
    return string.format("client_value:%s client_type%s server_value:%s", self.client_value, self.client_type, self.server_value);
end

return poker_data